home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / rpclib / clnt_raw.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  7KB  |  256 lines

  1. /*
  2.  * $Id: clnt_raw.c,v 1.3 1994/02/25 00:21:41 jraja Exp $
  3.  *
  4.  * $Log: clnt_raw.c,v $
  5.  * Revision 1.3  1994/02/25  00:21:41  jraja
  6.  * Changed malloc, calloc and free to mem_alloc, mem_calloc and mem_free,
  7.  * respectively.
  8.  *
  9.  * Revision 1.2  1993/11/10  01:32:06  jraja
  10.  * Fixed includes, added ANSI prototypes.
  11.  *
  12.  */
  13. /* @(#)clnt_raw.c    2.2 88/08/01 4.0 RPCSRC */
  14. /*
  15.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  16.  * unrestricted use provided that this legend is included on all tape
  17.  * media and as a part of the software program in whole or part.  Users
  18.  * may copy or modify Sun RPC without charge, but are not authorized
  19.  * to license or distribute it to anyone else except as part of a product or
  20.  * program developed by the user.
  21.  * 
  22.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  23.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  24.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  25.  * 
  26.  * Sun RPC is provided with no support and without any obligation on the
  27.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  28.  * modification or enhancement.
  29.  *
  30.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  32.  * OR ANY PART THEREOF.
  33.  * 
  34.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  35.  * or profits or other special, indirect and consequential damages, even if
  36.  * Sun has been advised of the possibility of such damages.
  37.  * 
  38.  * Sun Microsystems, Inc.
  39.  * 2550 Garcia Avenue
  40.  * Mountain View, California  94043
  41.  */
  42. #if !defined(lint) && defined(SCCSIDS)
  43. static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
  44. #endif
  45.  
  46. /*
  47.  * clnt_raw.c
  48.  *
  49.  * Copyright (C) 1984, Sun Microsystems, Inc.
  50.  *
  51.  * Memory based rpc for simple testing and timing.
  52.  * Interface to create an rpc client and server in the same process.
  53.  * This lets us similate rpc and get round trip overhead, without
  54.  * any interference from the kernal.
  55.  */
  56.  
  57. #include <sys/param.h>
  58. #include <rpc/rpc.h>
  59.  
  60. #define MCALL_MSG_SIZE 24
  61.  
  62. /*
  63.  * This is the "network" we will be moving stuff over.
  64.  */
  65. static struct clntraw_private {
  66.     CLIENT    client_object;
  67.     XDR    xdr_stream;
  68.     char    _raw_buf[UDPMSGSIZE];
  69.     char    mashl_callmsg[MCALL_MSG_SIZE];
  70.     u_int    mcnt;
  71. } *clntraw_private;
  72.  
  73. static enum clnt_stat    clntraw_call(CLIENT * h, u_long proc,
  74.                      xdrproc_t xdr_args, caddr_t args_ptr,
  75.                      xdrproc_t xdr_results,
  76.                      caddr_t results_ptr,
  77.                      struct timeval timeout);
  78. static void        clntraw_abort(CLIENT * h);
  79. static void        clntraw_geterr(CLIENT * h, struct rpc_err * errp);
  80. static bool_t        clntraw_freeres(CLIENT * cl, 
  81.                     xdrproc_t xdr_res, caddr_t res_ptr);
  82. static bool_t        clntraw_control(CLIENT * cl,
  83.                     u_int request, caddr_t info);
  84. static void        clntraw_destroy(CLIENT * h);
  85.  
  86. static struct clnt_ops client_ops = {
  87.     clntraw_call,
  88.     clntraw_abort,
  89.     clntraw_geterr,
  90.     clntraw_freeres,
  91.     clntraw_destroy,
  92.     clntraw_control
  93. };
  94.  
  95. /*
  96.  * Create a client handle for memory based rpc.
  97.  */
  98. CLIENT *
  99. clntraw_create(prog, vers)
  100.     u_long prog;
  101.     u_long vers;
  102. {
  103.     register struct clntraw_private *clp = clntraw_private;
  104.     struct rpc_msg call_msg;
  105.     XDR *xdrs = &clp->xdr_stream;
  106.     CLIENT    *client = &clp->client_object;
  107.  
  108.     if (clp == 0) {
  109.         clp = (struct clntraw_private *)mem_calloc(1, sizeof (*clp));
  110.         if (clp == 0)
  111.             return (0);
  112.         clntraw_private = clp;
  113.     }
  114.     /*
  115.      * pre-serialize the staic part of the call msg and stash it away
  116.      */
  117.     call_msg.rm_direction = CALL;
  118.     call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  119.     call_msg.rm_call.cb_prog = prog;
  120.     call_msg.rm_call.cb_vers = vers;
  121.     xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE); 
  122.     if (! xdr_callhdr(xdrs, &call_msg)) {
  123.         perror("clnt_raw.c - Fatal header serialization error.");
  124.     }
  125.     clp->mcnt = XDR_GETPOS(xdrs);
  126.     XDR_DESTROY(xdrs);
  127.  
  128.     /*
  129.      * Set xdrmem for client/server shared buffer
  130.      */
  131.     xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
  132.  
  133.     /*
  134.      * create client handle
  135.      */
  136.     client->cl_ops = &client_ops;
  137.     client->cl_auth = authnone_create();
  138.     return (client);
  139. }
  140.  
  141. static enum clnt_stat 
  142. clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
  143.     CLIENT *h;
  144.     u_long proc;
  145.     xdrproc_t xargs;
  146.     caddr_t argsp;
  147.     xdrproc_t xresults;
  148.     caddr_t resultsp;
  149.     struct timeval timeout;
  150. {
  151.     register struct clntraw_private *clp = clntraw_private;
  152.     register XDR *xdrs = &clp->xdr_stream;
  153.     struct rpc_msg msg;
  154.     enum clnt_stat status;
  155.     struct rpc_err error;
  156.  
  157.     if (clp == 0)
  158.         return (RPC_FAILED);
  159. call_again:
  160.     /*
  161.      * send request
  162.      */
  163.     xdrs->x_op = XDR_ENCODE;
  164.     XDR_SETPOS(xdrs, 0);
  165.     ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ;
  166.     if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
  167.         (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
  168.         (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
  169.         (! (*xargs)(xdrs, argsp))) {
  170.         return (RPC_CANTENCODEARGS);
  171.     }
  172.     (void)XDR_GETPOS(xdrs);  /* called just to cause overhead */
  173.  
  174.     /*
  175.      * We have to call server input routine here because this is
  176.      * all going on in one process. Yuk.
  177.      */
  178.     svc_getreq(1);
  179.  
  180.     /*
  181.      * get results
  182.      */
  183.     xdrs->x_op = XDR_DECODE;
  184.     XDR_SETPOS(xdrs, 0);
  185.     msg.acpted_rply.ar_verf = _null_auth;
  186.     msg.acpted_rply.ar_results.where = resultsp;
  187.     msg.acpted_rply.ar_results.proc = xresults;
  188.     if (! xdr_replymsg(xdrs, &msg))
  189.         return (RPC_CANTDECODERES);
  190.     _seterr_reply(&msg, &error);
  191.     status = error.re_status;
  192.  
  193.     if (status == RPC_SUCCESS) {
  194.         if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
  195.             status = RPC_AUTHERROR;
  196.         }
  197.     }  /* end successful completion */
  198.     else {
  199.         if (AUTH_REFRESH(h->cl_auth))
  200.             goto call_again;
  201.     }  /* end of unsuccessful completion */
  202.  
  203.     if (status == RPC_SUCCESS) {
  204.         if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
  205.             status = RPC_AUTHERROR;
  206.         }
  207.         if (msg.acpted_rply.ar_verf.oa_base != NULL) {
  208.             xdrs->x_op = XDR_FREE;
  209.             (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
  210.         }
  211.     }
  212.  
  213.     return (status);
  214. }
  215.  
  216. static void
  217. clntraw_geterr(CLIENT * h, struct rpc_err * errp)
  218. {
  219. }
  220.  
  221.  
  222. static bool_t
  223. clntraw_freeres(cl, xdr_res, res_ptr)
  224.     CLIENT *cl;
  225.     xdrproc_t xdr_res;
  226.     caddr_t res_ptr;
  227. {
  228.     register struct clntraw_private *clp = clntraw_private;
  229.     register XDR *xdrs = &clp->xdr_stream;
  230.     bool_t rval;
  231.  
  232.     if (clp == 0)
  233.     {
  234.         rval = (bool_t) RPC_FAILED;
  235.         return (rval);
  236.     }
  237.     xdrs->x_op = XDR_FREE;
  238.     return ((*xdr_res)(xdrs, res_ptr));
  239. }
  240.  
  241. static void
  242. clntraw_abort(CLIENT * h)
  243. {
  244. }
  245.  
  246. static bool_t
  247. clntraw_control(CLIENT * cl, u_int request, caddr_t info)
  248. {
  249.     return (FALSE);
  250. }
  251.  
  252. static void
  253. clntraw_destroy(CLIENT * h)
  254. {
  255. }
  256.